home *** CD-ROM | disk | FTP | other *** search
/ Amiga Mag HDD Backup / Amiga Mag HDD Backup.zip / Amiga Mag HDD Backup / Alexander.img.bin / Alexander.img / 315 2 files Archive.sit / Any plain-text files / ? Any plain-text file 96 < prev    next >
Text File  |  1995-01-03  |  4KB  |  151 lines

  1. /*----------  INCLUDE HEADER FILE  ----------*/
  2.  
  3. #include "CanDoMJC.h"
  4.  
  5. /*----------  SUPPORT FUNCTIONS  ----------*/
  6.  
  7. void MJPlot(struct Window *w, WORD maxdwell, LONG scale,
  8.             struct ComplexRange *cr, struct complex *jc, UBYTE type)
  9. {
  10.    struct RastPort *rp;
  11.    struct complex c, z, zloop;
  12.    struct IntuiMessage *message;
  13.    WORD xstart=0, ystart=0, x, y, xend, yend;
  14.    WORD count;
  15.    DOUBLE rstep, istep, zrtemp;
  16.    ULONG oldIDCMPFlags;
  17.  
  18.    rp = w->RPort;
  19.    oldIDCMPFlags = w->IDCMPFlags;
  20.    ModifyIDCMP(w, MOUSEBUTTONS);
  21.  
  22.    xend = 8*(rp->BitMap->BytesPerRow)-1;
  23.    yend = (rp->BitMap->Rows)-1;
  24.    rstep = (cr->rmax - cr->rmin)*scale/xend;
  25.    istep = (cr->imax - cr->imin)*scale/yend;
  26.  
  27.    SetRast(rp,0);
  28.    if (type == MANDELBROT) {
  29.       for (c.i = cr->imax, y=ystart ; y<=yend ; c.i-=istep, y+=scale) {
  30.      if(message = (struct IntuiMessage *)GetMsg(w->UserPort)) {
  31.         ReplyMsg((struct Message *)message);
  32.         break;
  33.      } /* if */
  34.      for (c.r = cr->rmin, x=xstart ; x<=xend ; c.r+=rstep, x+=scale) {
  35.         zloop.r = zloop.i = 0.;
  36.         count = 0;
  37.  
  38.         do {
  39.            zrtemp = zloop.r*zloop.r - zloop.i*zloop.i + c.r;
  40.            zloop.i = 2.*zloop.r*zloop.i + c.i;
  41.            zloop.r = zrtemp;
  42.            if((zloop.r*zloop.r + zloop.i*zloop.i) > 4.) break;
  43.            ++count;
  44.         } while (count < maxdwell);
  45.  
  46.         SetAPen(rp, count);
  47.         if (scale == 1)
  48.            WritePixel(rp, x, y);
  49.         else
  50.            RectFill(rp, x, y, x+scale-1, y+scale-1);
  51.      } /* for */
  52.       } /* for */
  53.    } /* if */
  54.  
  55.    else if (type == JULIA) {
  56.       for (z.i = cr->imax, y=ystart ; y<=yend ; z.i-=istep, y+=scale) {
  57.          if(message = (struct IntuiMessage *)GetMsg(w->UserPort)) {
  58.             ReplyMsg((struct Message *)message);
  59.             break;
  60.          } /* if */
  61.          for (z.r = cr->rmin, x=xstart ; x<=xend ; z.r+=rstep, x+=scale) {
  62.             zloop.r = z.r;
  63.             zloop.i = z.i;
  64.             count = 0;
  65.  
  66.             do {
  67.                if((zloop.r*zloop.r + zloop.i*zloop.i) > 4.) break;
  68.                ++count;
  69.                zrtemp = zloop.r*zloop.r - zloop.i*zloop.i + jc->r;
  70.                zloop.i = 2.*zloop.r*zloop.i + jc->i;
  71.                zloop.r = zrtemp;
  72.             } while (count < maxdwell);
  73.  
  74.         SetAPen(rp, count);
  75.         if (scale == 1)
  76.            WritePixel(rp, x, y);
  77.         else
  78.            RectFill(rp, x, y, x+scale-1, y+scale-1);
  79.      } /* for */
  80.       } /* for */
  81.    } /* else if */
  82.  
  83.    ModifyIDCMP(w, oldIDCMPFlags);
  84.  
  85. } /* MJPlot */
  86.  
  87. void SetComplexRange(struct ComplexRange *r, DOUBLE rmin,
  88.                      DOUBLE rmax, DOUBLE imin, DOUBLE imax)
  89. {
  90.    r->rmin = rmin;
  91.    r->rmax = rmax;
  92.    r->imin = imin;
  93.    r->imax = imax;
  94. } /* SetComplexRange */
  95.  
  96.  
  97. /*---------------  MAIN PROGRAM  ---------------*/
  98.  
  99. LONG main (int argc, char *argv[])
  100. {
  101.    /* LOCAL VARIABLES */
  102.    
  103.    struct Window *CanDoWin;
  104.    struct ComplexRange mrange;
  105.    struct ComplexRange jrange; 
  106.    struct complex jc;
  107.  
  108.    char **dummy=NULL;
  109.    char MandOrJulia;
  110.  
  111.    WORD maxdwell;
  112.    WORD resolution;
  113.  
  114.    DOUBLE rmin, rmax, imin, imax;
  115.  
  116.    /* OPEN LIBRARIES */
  117.    
  118.    if (!OpenLibraries()) {
  119.       CloseLibraries();
  120.       return 1L;
  121.    } /* if */
  122.  
  123.    /* EXECUTE PROGRAM IF RIGHT NUMBER OF ARGUMENTS */
  124.    
  125.    if (argc >= 9) {
  126.       CanDoWin=(struct Window *)(strtoul(argv[1],dummy,10));
  127.       maxdwell=(WORD)(strtoul(argv[2],dummy,10));
  128.       resolution=(WORD)(strtoul(argv[3],dummy,10));
  129.       rmin=strtod(argv[4],dummy);
  130.       rmax=strtod(argv[5],dummy);
  131.       imin=strtod(argv[6],dummy);
  132.       imax=strtod(argv[7],dummy);
  133.       MandOrJulia=*(argv[8]);
  134.       
  135.       if (MandOrJulia == 'M') {
  136.         SetComplexRange(&mrange, rmin, rmax, imin, imax);
  137.         MJPlot(CanDoWin, maxdwell, resolution, &mrange, NULL, MANDELBROT);
  138.       } /* if */
  139.  
  140.       else if (MandOrJulia == 'J') {
  141.         jc.r=strtod(argv[9],dummy);
  142.         jc.i=strtod(argv[10],dummy);
  143.         SetComplexRange(&jrange, rmin, rmax, imin, imax);
  144.         MJPlot(CanDoWin, maxdwell, resolution, &jrange, &jc, JULIA);
  145.       } /* else if */
  146.    } /* if argc >= 2 */
  147.  
  148.    CloseLibraries();
  149.  
  150. } /* main */